home *** CD-ROM | disk | FTP | other *** search
- #ifdef DEBUG_EVENT
-
- #include <stdio.h>
- #include "EventPrivateLib.h"
-
- static Boolean debug_print_long_event_list = false;
- static Boolean debug_print_short_event_list = false;
- static Boolean debug_print_event = false;
- static Boolean debug_print_object = false;
-
- static const char *EventKindName(EventKindType kind)
- {
- int i;
- static struct {
- EventKindType kind;
- char *name;
- } names[EVENT_LAST+1] = {
- { EVENT_NONE, "NONE", },
- { EVENT_WINDOW, "WINDOW", },
- { EVENT_DIALOG, "DIALOG", },
- { EVENT_MODAL, "MODAL", },
- { EVENT_CONTROL, "CONTROL", },
- { EVENT_CHECKBOX, "CHECKBOX", },
- { EVENT_RADIO, "RADIO", },
- { EVENT_BUTTON, "BUTTON", },
- { EVENT_SBAR, "SBAR", },
- { EVENT_TXSCRL, "TXSCRL", },
- { EVENT_TXDOC, "TXDOC", },
- { EVENT_TXWIN, "TXWIN", },
- { EVENT_LIST, "LIST", },
- { EVENT_CLIPBOARD,"CLIPBOARD", },
- { EVENT_PROGRESS, "PROGRESS", },
- { EVENT_HELP, "HELP", },
- { EVENT_ABOUT, "ABOUT", },
- { EVENT_WINMENU, "WINMENU", },
- { EVENT_DEBUG, "DEBUG", },
- { EVENT_APPLICATION, "APPLICATION", },
- };
- for (i = 0; i < EVENT_LAST && kind != names[i].kind; i++)
- ;
- return((kind == names[i].kind) ? names[i].name : "UNKNOWN");
- }
-
- #include <stdarg.h>
-
- #ifdef TOO_SLOW
-
- #include "ResourceConstantsLib.h"
- #include "TextLib.h"
- #include "TextScrollLib.h"
- #include "WindowMenuLib.h"
-
- /* display debug text in a scrollable window */
- static void DebugPrint(const char *fmt, ...)
- {
- static WindowPtr dbgwin;
- static TextScrollHandle scrl;
- static Boolean printing;
- TextHandle text = NULL;
- Rect bounds;
- va_list ap;
- CStr255 s;
- char *p;
- TextStyle style;
-
- TRY {
- if (! printing) {
- printing = true;
- if (! dbgwin) {
- TRY {
- dbgwin = WinGet(RLW_TEXT);
- WinPortRect(win, &bounds);
- scrl = TxScrlBegin(dbgwin, &bounds, true, true);
- style.tsSize = 9;
- TxScrlSetStyle(scrl, doSize, &style);
- TxScrlWrap(scrl, false);
- WinTitleSet(dbgwin, "Debug");
- WinMenuAdd(dbgwin);
- WinShow(dbgwin);
- } CATCH {
- TxScrlEnd(scrl); scrl = NULL;
- WinEnd(dbgwin); dbgwin = NULL;
- } ENDTRY;
- }
- va_start(ap, fmt);
- vsprintf(s, fmt, ap);
- va_end(ap);
- for (p = s; *p; p++) {
- if (*p == '\n')
- *p = '\r';
- else if (*p == '\t')
- *p = ' ';
- }
- text = TxScrlText(scrl);
- TxSelect(text, TxLength(text), TxLength(text));
- TxInsert(text, s, strlen(s));
- TxScrlChanged(scrl);
- printing = false;
- }
- } CATCH {
- printing = false;
- } ENDTRY;
- }
-
- #else /* TOO_SLOW */
-
- static void DebugPrint(const char *fmt, ...)
- {
- va_list ap;
-
- va_start(ap, fmt);
- vprintf(fmt, ap);
- va_end(ap);
- }
-
- #endif /* TOO_SLOW */
-
- void EventPrintObject(const char *prompt, EventType *obj,
- const char *flagprompt, Boolean flag)
- {
- if (debug_print_object) {
- DebugPrint("%s: object=0x%lx, kind=%s, id=%ld, %s=%s\n",
- prompt, obj->object, EventKindName(obj->kind), obj->id,
- flagprompt, flag ? "true" : "false");
- }
- }
-
- /* print the focus list */
- void EventPrintList(const char *prompt, WindowPtr window, EventType *list)
- {
- CStr255 title;
- EventType *item = NULL;
-
- WinTitle(window, title);
- if (debug_print_long_event_list) {
- DebugPrint("%s: window = '%s' (0x%8.8lx)\n", prompt, title, window);
- DebugPrint(" objects = ");
- for (item = list; item; item = item->next)
- DebugPrint("%8.8lx ", item->object);
- DebugPrint("\n");
- DebugPrint(" kinds = ");
- for (item = list; item; item = item->next)
- DebugPrint("%-8.8s ", EventKindName(item->kind));
- DebugPrint("\n\n");
- }
- else if (debug_print_short_event_list) {
- DebugPrint("%s: window = '%s'; objects = ", prompt, title);
- for (item = list; item; item = item->next)
- DebugPrint("%s ", EventKindName(item->kind));
- DebugPrint("\n");
- }
- }
-
- /* print the event */
- void EventPrint(const char *prompt, EventRecord *event)
- {
- #define NEVENT (10)
- struct {
- int what;
- char *name;
- } names[NEVENT] = {
- { nullEvent, "nullEvent", },
- { mouseDown, "mouseDown", },
- { mouseUp, "mouseUp", },
- { keyDown, "keyDown", },
- { keyUp, "keyUp", },
- { autoKey, "autoKey", },
- { updateEvt, "updateEvt", },
- { diskEvt, "diskEvt", },
- { activateEvt, "activateEvt", },
- { osEvt, "osEvt", },
- };
- int i;
-
- if (debug_print_event) {
- for (i = 0; i < NEVENT && event->what != names[i].what; i++)
- ;
- if (i < NEVENT) {
- DebugPrint("%s: event->what = %s; event->message = 0x%.8lx\n",
- prompt, names[i].name, event->message);
- }
- }
- }
-
- #endif /* DEBUG_EVENT */
-